home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / bbsdoors / ckit258.zip / CKITDEMO.C < prev    next >
C/C++ Source or Header  |  1993-06-01  |  30KB  |  819 lines

  1. #include    "oldckit.h"          /* For version 2.x CKit           */
  2. #include    "ckit.h"             /* Include CKIT Header file!      */
  3. #include    "ckitdemo.h"         /* Include file for demo          */
  4. #include    <fcntl.h>
  5. #include    <process.h>
  6. #pragma check_stack (off)
  7.  
  8.  
  9. short       OPENED;             /* Flag to know if open_door has been called  */
  10. short       CLOSED;             /* Flag to know if close_door has beeb called */
  11. struct  ckitgeneric  ck_gen;    /* Used for non-support BBS file types        */
  12. /******************************************************************************
  13.  *                     Start of Main Program                                  *
  14.  *****************************************************************************/
  15. main(int argc, char **argv) {
  16. short   result, i;
  17. char    *ptr, *des;
  18. /******************************************************************************
  19. *                        USER adjustments                                     *
  20. * You will need to set these according to how you want CKIT to handle certain *
  21. * options.  See the CKIT.DOC for more information                             *
  22. * These are all Ckit options, if not defined it will use defaults             *
  23. *******************************************************************************/
  24.     FORCEOFFHOOK = TRUE;             /* Default is FALSE                      */
  25.     USERSFILE = FALSE;               /* Default is FALSE anyway...            */
  26.     NO_FKEYS = FALSE;                /* Default is FALSE anyway...            */
  27.     DOTS = FALSE;                    /* Default is FALSE anyway...            */
  28.     ck_NO_STATUS = FALSE;            /* Enable Status line on local screen    */
  29.     silent = FALSE;                  /* Turn on local beeps(default is FALSE) */
  30.     logoff_color = (green);          /* Logoff msg to green (default=magenta) */
  31.     ck_logoff_msgs = &logoffs[0];    /* Set message table to demo msgs        */
  32.     ck_gen_msgs    = &ckit_msgs[0];  /* Set message table to demo msgs        */
  33.     set_kybd_time(2,6);              /* Beep time 2, timeout 6 minutes        */
  34.     OPENED = FALSE;
  35.     if (argc > 1) {                  /* (default is 3, 5 minutes)             */
  36.         strupr(argv[1]);
  37.         if(strstr(argv[1], "CHAIN.TXT")) {  /* Check if WWIV */
  38.             result = read_WWIV();    /* Ckit doesn't support WWIV directly    */
  39.             if(result) {             /* so we will read the chain file        */
  40.                 result -= 1;
  41.                 print_msg(result, ckit_errors);
  42.                 if(!result) {
  43.                     printf(" %s\n", argv[1]);
  44.                 }
  45.                 exit(1);
  46.             }
  47.             ck_NOSYSTEM = TRUE;     /* Tell Ckit not to expect a filename */
  48.             ptr = &ck_gen.port[0];
  49.         } else {
  50.             ptr = argv[1];              /* Assume it is a system supported    */
  51.             ck_NOSYSTEM = FALSE;
  52.         }
  53.         if(USERSFILE) {
  54.             result = open_door(ptr,  argv[2], argv[3]); /* Need arg3 for port:AAAA:X       */
  55.         } else {
  56.             result = open_door(ptr,  argv[2]);   /* Need arg2 for port:AAAA:X       */
  57.         }
  58.         ck_graphics |= ck_ansi_ng;
  59.         if(!result) {
  60.             OPENED = TRUE;              /* Door has been opened               */
  61.             atexit(shut_down);          /* call shut_down at exit time        */
  62.         } else {
  63.             OPENED = FALSE;             /* Door open failed for some reason   */
  64.             print_msg(result-1, ckit_errors);
  65.             if(result <= 3) {
  66.                 printf("%s\n", argv[1]);
  67.             } else {
  68.                 if(result <= 6) {
  69.                     printf("%s\n", argv[2]);
  70.                 }
  71.             }
  72.             exit(1);
  73.         }
  74.         if(GENERIC) {       /* If generic.sys file, we need to know user name */
  75.             newline();
  76.             s_puts("Please enter first and last name (MAX 25) ->");
  77.             get_cmdline_raw(45);
  78.             strncpy(fullname, cmdline, sizeof(ck_fullname)-1);
  79.             i=1;
  80.             ptr = &ck_fullname[0];
  81.             des = &ck_firstname[0];     /* Copy firstname of fullname */
  82.             while((i < sizeof(ck_firstname)) && (*ptr != 0x20)) {
  83.                 *des++ = *ptr++;
  84.                 i++;
  85.             }
  86.             *des = '\0';        /* NULL terminate */
  87.         }
  88.         display_info();               /* Display user information  */
  89.         menu();                       /* Main program loop         */
  90.     }
  91.  return(0);
  92.  }
  93. /******************************************************************************
  94. *                       End of Main Program                                   *
  95. ******************************************************************************/
  96.  
  97. /******************************************************************************
  98. *                       Main Menu                                             *
  99. ******************************************************************************/
  100. void    menu(void) {
  101.     short   silent;
  102.  
  103.     silent = TRUE;
  104.     newline();
  105.     if(display_file("ckit.m")) {   /* If error display_file() return NON_ZERO */
  106.         newline();
  107.         printf("Error code %d\n", errno);
  108.     }
  109.     force_enter();
  110.     /* main command loop */
  111.     while(DUMP_USER != TRUE) {
  112.           /* prompt for input only if there is not a stacked command pending */
  113.         if ( strlen(cmdline) == 0) {
  114.             color(white);
  115.             newline();
  116.             s_puts("Main menu:\r\n");
  117.             color(red);
  118.         s_puts(" (I)  Display system information\r\n");
  119.             color(green);
  120.             s_puts(" (C)  Take a chance for more time online\r\n");
  121.             color(magenta);
  122.             s_puts(" (T)  Display a test pattern\r\n");
  123.             color(cyan);
  124.             s_puts(" (A)  Ansi graphics demo\r\n");
  125.             color(violet);
  126.             s_puts(" (D)  Display information on CKIT\r\n");
  127.             color(green);
  128.             s_puts(" (F)  Download CKIT.DOC using Zmodem \r\n");
  129.             color(yellow);
  130.             s_puts(" (Z)  Zip CKITDEMO.C  using PKZIP \r\n");
  131.             color(yellow);
  132.             s_puts(" (M)  Color Mode On/Off \r\n");
  133.             color(red);
  134.             s_puts(" (Q)  Return to PCBoard\r\n");
  135.             color(green);
  136.             s_puts(" (G)  Logoff  (Disconnect)\r\n");
  137.             color(cyan);
  138.             s_puts("\r\n\
  139. While you are sitting here at the command line. Press some extended key\
  140. board \r\nkeys. If you are on the remote end using Qmodem, go into the DOORWAY\r\n\
  141. mode. Remember this is just a demo/usage for scan_code, so it's nothing \
  142. fancy.\r\n");
  143.             color(yellow);
  144.             do {
  145.                 newline();
  146.         display_time();
  147.                 color(green);
  148.                 s_puts("Command? ");
  149.                 get_cmdline();          /* read input into 'cmdline'  */
  150.  
  151.             } while((DUMP_USER != TRUE) && (strlen(cmdline) == 0) && (scan_code == 0));
  152.         }
  153.         if (DUMP_USER == TRUE) {
  154.             exit(1);
  155.         }
  156.         if (scan_code != 0) {
  157.             color(white);
  158.             read_scancode();
  159.         newline();
  160.         }
  161.         if (get_nextpar()) {  /* scan next parameter from cmdline into par */
  162.             newline();
  163.       /* process commands */
  164.             switch ( par[0] ) {
  165.                 case 'A':
  166.                 ansi_demo();
  167.                 break;
  168.                 case 'C':
  169.                 take_chance();
  170.                 break;
  171.                 case 'I':
  172.                 display_info();
  173.                 break;
  174.                 case 'T':
  175.                 test_pattern();
  176.                 break;
  177.                 case 'D':
  178.                 color(cyan);
  179.                 strcpy(error_msg11, "\a\nUnable to locate CKIT.DOC");
  180.                 if(display_file(doc_filename)) {
  181.                     newline();
  182.                     printf("Error code %d\n", errno);
  183.                 };
  184.                 break;
  185.                 case 'F':
  186.                 color(cyan);
  187.                 filexfer();
  188.                 break;
  189.                 case 'Z':
  190.                 color(cyan);
  191.                 zipfile();
  192.                 break;
  193.                 case 'M':
  194.                 graphics ^= TRUE; /* Toggle graphics */
  195.                 ansi_ng |= TRUE;  /* Set ansi_ng (we only want to turn off color) */
  196.                 ck_set_ANSI(ansi_ng | graphics);
  197.                 break;
  198.                 case 'Q':
  199.                 option = EXITDOOR;
  200.                 return;
  201.                 case 'G':
  202.                 option = LOGOFF;
  203.                 return;
  204.                 default:
  205.                 newline();
  206.                 color(magenta);
  207.                 if(silent) {
  208.                     send_byte(BELL);
  209.                 } else {
  210.                     s_putc(BELL);
  211.                 }
  212.                 s_printf(" '%s' is not allowed!  Try again: %s", par, firstname);
  213.                 *cmdline = 0;
  214.                 break;
  215.         }
  216.         }
  217.     }
  218. }
  219.  
  220. /******************************************************************************
  221. *                       Display User information                              *
  222. ******************************************************************************/
  223. void display_info(void) {
  224.     clr_screen();
  225.     newline();
  226.     color(white);
  227.     s_printf("%s, Here is your User information:", firstname);
  228.     color(green);
  229.     newline();
  230.     newline();
  231.     s_putv("  Fullname        = ",fullname,"\r\n",NULL); /* could use sprintf() also */
  232.  
  233. /*    if(!GENERIC) { */
  234.         if (!PCB &!RBBS) {
  235.             s_printf("  Phone number(s) = ");
  236.         }
  237.         if (!WILDCAT && !PCB && !RBBS) {
  238.             s_printf("User Business - %s", user.bphone);
  239.         }
  240.         if (!PCB && !RBBS) {
  241.             s_printf("   Home - %s", user.phone);
  242.         newline();
  243.         }
  244.         if (!PCB) {
  245.             s_printf("  City            = %s\r\n",user.city);
  246.         }
  247.         s_printf("  Modem Baud Rate = %s\r\n",baud_rate);
  248.         if(!RBBS) {
  249.             s_printf("  DTE Baud Rate   = %s\r\n",bps_open);
  250.         }
  251.         s_printf("  Minutes left    = %d\r\n",min_left+time_credit);
  252.  
  253.         if (!PCB && !RBBS) {
  254.             s_printf("  Protocol is     = %s\r\n",protocol);
  255.     }
  256.  
  257.         if (!WILDCAT && !PCB && !RBBS) {
  258.             s_printf("  Last call date  = %s\r\n",user.last_date);
  259.         }
  260.  
  261.         if (!PCB && !WILDCAT && !RBBS) {
  262.             s_printf("  Event runs at   = %s\r\n",event_time);
  263.             s_printf("  Total K bytes   = %s",download_Kbytes);
  264.             newline();
  265.             s_printf("  Total K bytes   = %s\r\n",upload_Kbytes);
  266.         }
  267.         if (!PCB && !RBBS) {
  268.         s_printf("  # of Downloads  = %s",dload_total);
  269.             s_printf("  Today's K bytes = %s\r\n",daily_bytes);
  270.             s_printf("  Allowed K bytes = %d\r\n",dload_limit);
  271.             s_printf("  # of Uploads    = %s\r\n",upload_total);
  272.             s_printf("  Your birthday   = %s\r\n",caller_bday);
  273.             s_printf("  Last file scan  = %s\r\n",last_file_scan);
  274.         }
  275.         if (WILDCAT) {
  276.             s_printf("  Monitor type    = %s\r\n", monitor_type);
  277.             s_printf("  High msg. read  = %s\r\n", high_msg);
  278.             s_printf("  Door opened     = %s\r\n", door_opened);
  279.         }
  280.         if(RBBS) {
  281.         s_printf("  BBS system name = %s", BBSname);
  282.             newline();
  283.         }
  284.         s_puts("  Graphic         = ");
  285.         if  (graphics) {
  286.             s_puts("ON");
  287.         } else {
  288.             s_puts("OFF");
  289.         }
  290.         newline();
  291.         if(!Digiboard) {
  292.             s_printf("  Connected to port %s", aport);
  293.         } else {
  294.             s_printf("  Connected to Digiboard channel %d", port);
  295.         }
  296.         newline();
  297.         if(!RBBS) {
  298.         s_puts("  Error correction = ");
  299.             if  (error_connection) {
  300.                 s_puts("YES");
  301.             } else {
  302.                 s_puts("NO");
  303.             }
  304.         newline();
  305.         }
  306.         s_printf("  Page length     = %d\r\n",page_length);
  307.         color(yellow);
  308.         newline();
  309.         force_enter();
  310. /*
  311.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  312.  */
  313.  
  314. /*    } */
  315. }
  316.  
  317. /******************************************************************************
  318. *                       ANSI Demo                                             *
  319. ******************************************************************************/
  320. void ansi_demo(void) {
  321.  
  322.     short x,y;
  323.     register    short  i;
  324.  
  325.     if (graphics || ansi_ng) {  /* Check if user is in ANSI mode */
  326.         clr_screen();
  327.         for (y=2; y < 24; y++) {
  328.             pos_cursor(y,1);
  329.             s_puts("│");
  330.             pos_cursor(y,79);
  331.             s_puts("│");
  332.         }
  333.         x = 2;
  334.         pos_cursor(1,x);
  335.         for(i = 0; i <= 1; i++) {
  336.             while(x < 79) {
  337.         s_puts("─");
  338.                 x++;
  339.             }
  340.             x = 2;
  341.             pos_cursor(23,x);
  342.         }
  343.         pos_cursor(1,1);
  344.         s_puts("┌");
  345.         pos_cursor(1,79);
  346.         s_puts("┐");
  347.         pos_cursor(23,1);
  348.         s_puts("└");
  349.         pos_cursor(23,79);
  350.     s_puts("┘");
  351.  
  352.         for(i = blue; i <= white; i++) {
  353.             color(i);
  354.             pos_cursor(i-8+3,11);
  355.             s_puts("ANSI Color display");
  356.         }
  357.         for(i = grey; i >= dkblue; i--) {
  358.             color(i);
  359.             pos_cursor(i+3, 50);
  360.             s_puts("ANSI Color display");
  361.         }
  362.         color(red);
  363.     pos_cursor(13,34);
  364.         s_puts("C - K I T");
  365.         color(yellow);
  366.         pos_cursor(16,14);
  367.         s_puts("This is only a SMALL sample of what C-Kit can do! ");
  368.         color(red);
  369.         pos_cursor(20,26);
  370.     } else {
  371.         clr_screen();
  372.         newline();
  373.         s_puts("ANSI demo available only in GRAPHICS mode.\r\n");
  374.     }
  375.     force_enter();
  376.  
  377. /*
  378.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  379.  */
  380.     clr_screen();
  381. }
  382.  
  383. /*****************************************************************************
  384.  *  Open  door                                                               *
  385.  *****************************************************************************/
  386. void    test_pattern(void) {
  387.     int  i;
  388.  
  389.     newline();
  390.     for (i = 1; i < 21; i++) {
  391.            s_puts("(1234567890-abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789)\r\n");
  392.     }
  393. /*
  394.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  395.  */
  396.  
  397. }
  398.  
  399.  
  400. /*****************************************************************************
  401.  *  Filexfer doc file                                                        *
  402.  *  Example using CKIT's own ck_dos_shell (which uses spawnlp())              *
  403.  *****************************************************************************/
  404. void    filexfer(void) {
  405.     char    dszname[12];
  406.     short   errorlevel;
  407.     color(green);
  408.     strcpy(dszname, "PCBDSZ.BAT");
  409. //    strcpy(dszname, "DSZ.COM");
  410.     if(!FOSSIL && !local && !Digiboard) {
  411.     s_printf("\nReady to send %s. Press <ENTER> to begin.",doc_filename);
  412.     while(DUMP_USER != TRUE) {
  413.         if( check_CR() ) {
  414.         break;
  415.         }
  416.     }
  417.     if(strstr(dszname, ".BAT")) {
  418.         sprintf(zmodem_cmds, "/C %s %X, %X %s", \
  419.             dszname, uart_base, irq, doc_filename);
  420.         errorlevel = ck_dos_shell(getenv("COMSPEC"), zmodem_cmds);
  421.     } else {
  422.         sprintf(zmodem_cmds, "portx %X, %X sz %s", \
  423.             uart_base, irq, doc_filename);
  424.         errorlevel = ck_dos_shell(dszname, zmodem_cmds);
  425.     }
  426.     if(errorlevel) {
  427.         s_puts("\n\aTransfer aborted");
  428.     } else {
  429.         s_puts("\nTransfer complete");
  430.     }
  431.     } else {
  432.     s_puts("\n\r Not supported with /DIGIBOARD/FOSSIL/LOCAL usage.");
  433.     }
  434. /*
  435.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  436.  */
  437. }
  438.  
  439. /*****************************************************************************
  440.  *  File Compression                                                         *
  441.  *  Example using ck_shell_entry() and ck_shell_exit() and C's spawnlp()     *
  442.  *****************************************************************************/
  443. void    zipfile(void) {
  444.     char    *cmdcom;
  445.     char    pkzname[12];
  446.     short   errorlevel;
  447.     color(green);
  448.     pkzname[9] = '\0';
  449.     strcpy(pkzname, "ZIP.BAT");
  450. //    strcpy(pkzname, "PKZIP");
  451.     s_printf("\nReady to compress CKIT.DOC Press <ENTER> to begin.");
  452.     while(DUMP_USER != TRUE) {
  453.         if( check_CR() ) {
  454.         break;
  455.         }
  456.     }
  457.     if(strstr(pkzname, ".BAT")) {
  458.         cmdcom = getenv("COMSPEC");
  459.         ck_shell_entry();               /* Prepare CKIT for a DOS Shell */
  460.         sprintf(pkzcmds, "/C %s -a %s ckit.doc", \
  461.                 pkzname, zip_filename);
  462.         errorlevel = spawnlp(P_WAIT, cmdcom, cmdcom, pkzcmds, NULL);
  463.         ck_shell_exit();                /* Clean up after a shell  */
  464.     } else {
  465.         ck_shell_entry();               /* Prepare CKIT for a DOS Shell */
  466.         sprintf(pkzcmds, "-a %s ckit.doc", zip_filename);
  467.         errorlevel = spawnlp(P_WAIT, pkzname, pkzname, pkzcmds, NULL );
  468.         ck_shell_exit();                /* Clean up after a shell  */
  469.     }
  470.     if(errorlevel) {
  471.         s_puts("\n\aError compressing file.");
  472.     } else {
  473.         s_puts("\nCompression complete");
  474.     }
  475. /*
  476.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  477.  */
  478. }
  479. /******************************************************************************
  480. *  Demostrate scan_code usage                                                 *
  481. ******************************************************************************/
  482. void    read_scancode(void) {
  483.  
  484.      newline();
  485.      newline();
  486.       /* process scancodes */
  487.     switch(scan_code) {
  488.         case 0x3B00:
  489.         s_puts("You pressed F1");
  490.         break;
  491.         case 0x3C00:
  492.         s_puts("You pressed F2");
  493.         break;
  494.         case 0x3D00:
  495.         s_puts("You pressed F3");
  496.     break;
  497.         case 0x3E00:
  498.         s_puts("You pressed F4");
  499.         break;
  500.         case 0x3F00:
  501.         s_puts("You pressed F5");
  502.         break;
  503.         case 0x4000:
  504.         s_puts("You pressed F6");
  505.         break;
  506.         case 0x4100:
  507.         s_puts("You pressed F7");
  508.         break;
  509.     case 0x4200:
  510.         s_puts("You pressed F8");
  511.         break;
  512.         case 0x4300:
  513.         s_puts("You pressed F9");
  514.         break;
  515.         case 0x4400:
  516.         s_puts("You pressed F10");
  517.         break;
  518.         case 0x4800:
  519.         s_puts("You pressed UP Arrow");
  520.         break;
  521.         case 0x5000:
  522.     s_puts("You pressed Dn Arrow");
  523.         break;
  524.         case 0x4D00:
  525.         s_puts("You pressed R Arrow");
  526.         break;
  527.         case 0x4B00:
  528.         s_puts("You pressed L Arrow");
  529.         break;
  530.         case 0x4900:
  531.         s_puts("You pressed PgUp");
  532.         break;
  533.         case 0x5100:
  534.         s_puts("You pressed PgDn");
  535.     break;
  536.         case 0x5200:
  537.         s_puts("You pressed Insert");
  538.         break;
  539.         case 0x5300:
  540.         s_puts("You pressed Delete");
  541.         break;
  542.         case 0x4700:
  543.         s_puts("You pressed Home");
  544.         break;
  545.         case 0x4F00:
  546.         s_puts("You pressed End");
  547.         break;
  548.     case 0x4A00:
  549.         s_puts("You pressed Grey - ");
  550.         break;
  551.         case 0x4E00:
  552.         s_puts("You pressed Grey + ");
  553.         break;
  554.         default:
  555.         break;
  556.     }
  557.     newline();
  558.     s_puts(" - Press a key to continue - ");
  559.     newline();
  560.     while(!(wait_keypress())) {
  561.     }
  562. }
  563.  
  564. /*****************************************************************************
  565.  *  Take a chance on on-line time                                            *
  566.  *****************************************************************************/
  567. void    take_chance(void) {
  568.     char    thinking_of[5];
  569.  
  570.     if(PCB) {
  571.         *cmdline = 0;
  572.         itoa(random(10),thinking_of,10);
  573.         if ( strlen(cmdline) == 0) {
  574.         color(cyan);
  575.             s_puts("I'm thinking of a number from 0 to 9.  If you guess the\r\n");
  576.             s_puts("number, you will be given an extra 10 minutes online.  If you\r\n");
  577.             s_puts("get it wrong, your time will be reduced by 2 minutes.\r\n");
  578.             newline();
  579.             color(yellow);
  580.             s_puts("What's your guess? ");
  581.             get_cmdline();
  582.             newline();
  583.         }
  584.         if (get_nextpar()) {  /* scan next parameter from cmdline into par */
  585.             if (!strcmpi(thinking_of, par)) {
  586.                 color(green);
  587.         s_puts("That's right!  You get a 10 minute bonus!");
  588.                 adjust_time_allowed(10);
  589.             } else {
  590.                 color(blue);
  591.                 s_printf("Wrong! You lose 2 minutes! I was thinking of %s.",thinking_of);
  592.                 adjust_time_allowed(-2);
  593.             }
  594.         }
  595.     } else {
  596.         newline();
  597.         s_puts("Take chance only available with PCBOARD.SYS usage.\r\n");
  598.     }
  599. }
  600.  
  601. /****************************************************************************
  602.  *      Printf() function for sending output to port                        *
  603.  ****************************************************************************/
  604. void s_printf(char *s_format,...) {
  605.     va_list arg_pointer;
  606.     char buffer[256];
  607.     va_start(arg_pointer, s_format);
  608.     vsprintf(buffer, s_format, arg_pointer);
  609.     s_puts(buffer);
  610.     va_end(arg_pointer);
  611. }
  612.  
  613. /****************************************************************************
  614.  *      Close door, reset vectors etc.                                      *
  615.  *  Need in case of a run time error occurs in door                         *
  616.  ****************************************************************************/
  617.  void   shut_down(void) {
  618.     if(OPENED && !CLOSED) {
  619.         close_door();
  620.         CLOSED = TRUE;
  621.     }
  622. }
  623.  
  624. /*****************************************************************************
  625.  *  Print (XXX used, XXX left)  (time in minutes)                            *
  626.  *****************************************************************************/
  627. void display_time(void) {
  628.         color(yellow);
  629.         s_puts("(");
  630.         color(green);
  631.         s_printf("%d used, ", system_time_used()+prev_used);
  632.         color(red);
  633.         s_printf("%d left",  mins_left_system()+time_credit);
  634.         color(yellow);
  635.         s_puts(") ");
  636.  }
  637.  
  638. /*****************************************************************************
  639.  *  Prints messages, enter with msg table to use                             *
  640.  *****************************************************************************/
  641. void    print_msg(short index, char **msg_table) {
  642.     printf(msg_table[index]);
  643. }
  644.  
  645. /*****************************************************************************
  646.  *  Send a single byte to the remote only                                    *
  647.  *****************************************************************************/
  648. void    send_byte(BYTE data) {
  649.     BYTE byte_out[2];
  650.     *byte_out = data;
  651.     *(byte_out+1) = 0x00;
  652.     transmit_data(byte_out);
  653. }
  654.  
  655. /****************************************************************************
  656.  * This #if is needed since TURBOC has it's own random() function           *
  657.  * This is needed for this demo source code only.                           *
  658.  ****************************************************************************/
  659. #if COMPILER == MICROSOFT
  660.     int   random(short Modulo) {
  661.         short   seed;
  662.     check_time_left();
  663.         seed = system_time_HHMMSS[7] - 0x30;    /* Strip ASCII off */
  664.         return(RAND(seed));
  665.     }
  666. #else    /* TURBO C */
  667.     //do nothing
  668. #endif
  669.  
  670. /****************************************************************************
  671.  *    Read a WWIV v.4.07 or later CHAIN.TXT file.                           *
  672.  ****************************************************************************/
  673. short   read_WWIV(void) {
  674. struct  ckitgeneric  *ck_info;
  675. char    *des, *src, *str_ptrs[30], *tmp;
  676. size_t  bytes_read;
  677. short   wwiv_handle, i;
  678. float   fl;
  679. ck_info = &ck_gen;
  680.  
  681.     if(!(des = create_buffer(BUFFER_SIZE))) {
  682.     return(9);
  683.     }
  684.     if(!(wwiv_handle = open_file("chain.txt"))) {
  685.     free(des);
  686.     return(1);
  687.     }
  688.     if(!(bytes_read = ck_read_record(wwiv_handle, des, BUFFER_SIZE))) {
  689.     free(des);
  690.     return(1);
  691.     }
  692.     tmp = des;
  693.     dosclose(wwiv_handle);
  694.     parse_to_C(des, bytes_read, &str_ptrs[0], sizeof(str_ptrs)/sizeof(void *));
  695.     ck_user_record = atoi(str_ptrs[0]);
  696.  
  697.     /* Copy fullname and firstname */
  698.     strncpy(ck_fullname,str_ptrs[2], sizeof(ck_fullname)-1);
  699.     i=1;
  700.     src = str_ptrs[2];
  701.     des = &ck_firstname[0];
  702.     while((i < sizeof(ck_firstname)) && (*src != 0x20)) {
  703.         *des++ = *src++;
  704.         i++;
  705.     }
  706.     *des = '\0';        /* NULL terminate */
  707.  
  708.     /* Set user page length */
  709.     ck_page_length = atoi(str_ptrs[9]);
  710.  
  711.     /* Set security levels */
  712.     strncpy(ck_security_level, str_ptrs[10], sizeof(ck_security_level)-1);
  713.     ck_user.security = atoi(str_ptrs[10]);  /* For status line */
  714.  
  715.     /* Set graphics mode */
  716.     if((ck_graphics = atoi(str_ptrs[13])) != 0) { /* OK to use ANSI? 0=No 1=YES */
  717.         ck_set_ANSI(ck_graphics);       /* Turn on ANSI in CKIT */
  718.     }
  719.  
  720.     /* Set up ck_open_door() info in ck_gen structure */
  721.     /* Read com port */
  722.     strcpy(ck_info->port, "COM0:");        /* Local is default */
  723.     if(atoi(str_ptrs[14])) {               /* Local or Remote? 0 = LOC 1 = REMOTE */
  724.         ck_info->port[3] = *str_ptrs[20];  /* Set port number */
  725.     }
  726.  
  727.     /* Read secs left, convert to mins */
  728.     sscanf(str_ptrs[15],"%f",&fl);
  729.     ck_info->min_left = (double)fl/60;
  730.  
  731.     /* Read rest of information for status line */
  732.     strncpy(ck_baud_rate, str_ptrs[19], sizeof(ck_baud_rate)-1);
  733.     strncpy(ck_bps_open, str_ptrs[19], sizeof(ck_baud_rate)-1);
  734.     strncpy(ck_BBSname, str_ptrs[21], sizeof(ck_BBSname)-1);
  735.     free(tmp);
  736.     strcpy(ck_node, "0");           /* So status line looks correct */
  737.     return(0);
  738. }
  739.  
  740. /*****************************************************************************
  741.  *  Open a file for read only, share deny none                               *
  742.  *****************************************************************************/
  743. short  open_file(char *filename) {
  744. short filehandle;
  745. #if COMPILER == MICROSOFT
  746.     if ((dosopen(filename, O_RDONLY | SH_DENYNO, &filehandle)) != 0) {
  747.         return(FALSE);
  748.     }
  749. #else    /* TURBO C */
  750.     if ((filehandle = dosopen(filename, O_RDONLY | O_DENYNONE)) == -1) {
  751.         return(FALSE);
  752.     }
  753. #endif
  754. return(filehandle);
  755. }
  756.  
  757. /*****************************************************************************
  758.  *  Read buffersize bytes from file to buffer pointer                        *
  759.  *****************************************************************************/
  760. size_t ck_read_record(short handle, BYTE *record, size_t readcount) {
  761. short    bytes_read;
  762.  
  763. #if COMPILER == MICROSOFT
  764.     if ((dosread(handle, record, readcount, &bytes_read)) != 0) {
  765.     return(FALSE);
  766.     }
  767. #else   /* TURBO C */
  768.     if((bytes_read = dosread(handle, record, readcount)) == -1) {
  769.     return(FALSE);
  770.     }
  771. #endif
  772. return(bytes_read);
  773. }
  774.  
  775. /*****************************************************************************
  776.  *  Allocate a buffer for file use                                           *
  777.  *****************************************************************************/
  778. char * create_buffer(size_t size) {
  779. char *buffer;
  780. if ((buffer = (char *)malloc(size)) == NULL) {
  781.     return(FALSE);
  782. }
  783. return(buffer);
  784. }
  785.  
  786. /*****************************************************************************
  787.  * Parse strings ending (with 0D/AH) to NULL terminated 'C' strings          *
  788.  * Enter with buffer to parse and size of buffer.                            *
  789.  * It will write the C strings back to the same buffer it is reading from    *
  790.  * and return the number of line converted (strings)                         *
  791.  *****************************************************************************/
  792. short   parse_to_C(register char *buffer, size_t bytes_to_do, char **dat_ptrs, short array_size) {
  793. register char    *buffer1;
  794. short   line_number = 0;
  795.  
  796. buffer1 = buffer;
  797. dat_ptrs[line_number] = buffer;
  798. while((bytes_to_do != 0) && (line_number < array_size)) {
  799.     if(*buffer != 0x0D && *buffer != 0x1A) {  /* Check if C/R or EOF     */
  800.             if(*buffer == '\0') {
  801.                 dat_ptrs[line_number] = buffer1+1; /* Save ptr to string */
  802.             }
  803.             *buffer1++ = *buffer++; /* copy byte                         */
  804.             bytes_to_do -= 1;       /* Decrement number of bytes to do   */
  805.     } else {
  806.     if(*++buffer == 0x0A) {     /* Check for line feed               */
  807.             *buffer = '\0';         /* Terminate string with NULL        */
  808.             line_number += 1;       /* Increment line counter            */
  809.     } else {
  810.             *buffer1++ = *buffer;
  811.         }
  812.         bytes_to_do -= 1;           /* Decrement number of bytes to do   */
  813.     }
  814. }
  815. return(line_number);                /* Return number of lines read       */
  816. }
  817. /****************************************************************************/
  818. /************************ E N D  O F   M O D U L E **************************/
  819.